package com.example.eeuse.model;

import com.example.eeuse.util.KibanaUtil;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class KibanaBaseReq {
    private int size;
    private Query query;


    public  void addRange(Range range)
    {
        this.getQuery().getBool().addRange(range);
    }
    @Data
    public static class Query{
        private Bool bool;
        public Query(Bool bool)
        {
            this.bool=bool;
        }
    }
    @Data
    public static class  Bool{
        private List<Object> must;
        private double boost=1.0;
        public Bool(List must)
        {
            this.must=must;
        }
        public void addRange(Range range)
        {
            must.add(range);
        }
    }
    @Data
    public static class Range{
        private Map<String,Map<String,String>> range;
        //gt大于,lt小于，gte大于等于,lte小于等于
        public Range(String key,String from,String to)
        {
            Map<String,String> fromTo=new HashMap<>();
            fromTo.put("gt",from);
            fromTo.put("lte",to);
            range=KibanaUtil.createHashMap(key,fromTo);

        }
    }
    @Data
    public static class Must{
        private Map<String,String> match;
        public Must(Map<String,String> match)
        {
            this.match=match;
        }

        public Must(String key,String val)
        {
            this.match= KibanaUtil.createHashMap(key,val);
        }
    }


    /*
    "{\n" +
                    "  \"size\": 100, \n" +
                    "  \"query\": {\n" +
                    "    \"bool\": {\n" +
                    "      \"must\": [\n" +
                    "          {\n" +
                    "            \"match\": {\n" +
                    "            \"ARR.keyword\": \""+arr+"\"\n" +
                    "            }\n" +
                    "          },\n" +
                    "          {\n" +
                    "            \"match\": {\n" +
                    "            \"DEP.keyword\": \""+dep+"\"\n" +
                    "            \n" +
                    "            }\n" +
                    "          },\n" +
                    "          {\n" +
                    "            \"match\": {\n" +
                    "            \"SAMPLE_NODE.keyword\": \"SAMPLE_RESPONSE\"\n" +
                    "            \n" +
                    "            }\n" +
                    "          },\n" +
                    "          {\n" +
                    "            \"range\": {\n" +
                    "              \"@timestamp\": {\n" +
                    "                \"from\": \""+beginTime+"\",\n" +
                    "                \"to\": \""+endTime+"\"\n" +
                    "              }\n" +
                    "            }\n" +
                    "          }\n" +
                    "      ]\n" +
                    "      \n" +
                    "    }\n" +
                    "    }\n" +
                    "}\n";
     */
}
